from Goldenberry.optimization.ga.GbSolutionRepMgr.BinaryEncoders import DirectBinaryMapping, GrayCodeMapping
from Goldenberry.optimization.ga.GbSolutionRepMgr.RealEncoders import DirectMappingEscaledUnitInterval, DirectRealMapping, FloatToBinary

class EncoderFactory(object):
    """description of class"""
    """def get_class(self, kls):
        parts = kls.split('.')
        module = ".".join(parts[:-1])
        m = __import__(kls)
        for comp in parts[1:]:
            m = getattr(m, comp)            
        return m"""

    def get_encoder(self, encode_function, range_min, range_max):
       # a = self.get_class(encode_function)
        if encode_function == 'DirectBinaryMapping':
            return DirectBinaryMapping()          
        elif encode_function == 'GrayCodeMapping':
            return GrayCodeMapping() 
        elif encode_function == 'DirectMappingEscaledUnitInterval':
            return DirectMappingEscaledUnitInterval(range_min, range_max) 
        elif encode_function == 'DirectRealMapping':
            return DirectRealMapping() 
        else:
            return FloatToBinary(range_min, range_max) 


